package assignment;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class HowManyDays {

	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<String> inputsList = new ArrayList<String>();
		System.out.print("Enter First Date (mm-dd-yyyy):");
		inputsList.add(br.readLine());
		System.out.print("Enter Second Date (mm-dd-yyyy):");
		inputsList.add(br.readLine());

		SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
		
		List<Date> datesList = new ArrayList<Date>();
		
		//test dates
		for (String d : inputsList) {
			Date testDate = null;
			String delims = "[-]";
			String[] tokens = d.split(delims);
			
			for (int i = 0; i < tokens.length; i++) {
				String string = tokens[i];
				switch (i) {
				case 0:
					//should be month
					int month = Integer.parseInt(string);
					if(month < 1 || month > 12) {
						throw new IllegalArgumentException("Invalid Month Entered!");
					}
					break;
				case 1:
					//should be day
					int day = Integer.parseInt(string);
					if(day < 1 || day > 31) {
						throw new IllegalArgumentException("Invalid Day Entered!");
					}
					break;
				case 2:
					//should be year
					int year = Integer.parseInt(string);
					if(year < 1800 || year > 2100) {
						throw new IllegalArgumentException("Invalid Year Entered!");
					}
					break;
				}
			}
			
			try {
				testDate = sdf.parse(d);
				System.out.println(testDate);
				datesList.add(testDate);
			} catch (ParseException e) {
				System.out.println("Invalid Format! Date should be entered as mm-dd-yyyy.");
			}
		}
		
		long diff = Math.abs(datesList.get(0).getTime()-datesList.get(1).getTime());
		long diffDays = diff / (24*60*60*1000);
		System.out.println("There are " + diffDays + " days between " + datesList.get(0) + " and " + datesList.get(1) + ".");
	}
}
